<?php namespace App\Controllers;

use App\Models\SelectionModel;

class Dashboard extends BaseController
{
    public function index()
    {
        $model = new SelectionModel();
        
        // 获取所有提交的数据
        $selections = $model->findAll();
        
        // 计算统计数据
        $total = count($selections);
        $class1Count = $model->where('class_name', '五（1）班')->countAllResults();
        $class2Count = $model->where('class_name', '五（2）班')->countAllResults();
        
        // 获取各研学地点的选择次数
        $locationCounts = $model->select('first_choice, COUNT(*) as count')
                             ->groupBy('first_choice')
                             ->orderBy('count', 'DESC')
                             ->findAll();
        
        $data = [
            'selections'     => $selections,
            'total'          => $total,
            'class1Count'    => $class1Count,
            'class2Count'    => $class2Count,
            'locationCounts' => $locationCounts
        ];
        
        return view('dashboard/index', $data);
    }
}